# -*- coding: UTF-8 -*-  
#A Test to Return a AES-File of a Common File
#使用脚本时请先在脚本以及资源所在的目录创建一个res文件夹用于保存生成的文件

import os
import shutil

def doWork(name):
	fp1 = file('%s.js'%(name),'r')
	fp2 = file('%s_bak.js'%(name),'w')
	for s in fp1.readlines():
		fp2.write(s.replace('var $protobuf = require("protobufjs/minimal");','var $protobuf = protobuf;'))
	fp1.close();
	fp2.close();

def doCopy(name):
	shutil.copyfile('%s_bak.js'%(name), '../assets/Script/proto/%s.js'%(name))
	os.remove('%s_bak.js'%(name))
    
if __name__ == '__main__':
    gamename = 'septdata'
    osCmd = 'pbjs -t static-module --keep-case -w commonjs -o septdata.js septdata.proto'
    os.system(osCmd)
    osCmd = 'pbts -m -o septdata.d.ts septdata.js'
    os.system(osCmd)
    doWork(gamename)
    doCopy(gamename)
    shutil.copyfile('septdata.d.ts', '../assets/Script/proto/septdata.d.ts')
    print 'create protobuf js over'

